#include<iostream>
#include<vector>

using namespace std;

void func1()
{
	string s;
	cin >> s;
	int p;
	cin >> p;
	s = " " + s;
	int n = s.size();
	const int mod = 1e9 + 7;
	vector<vector<int>> f(n+1, vector<int>(p));
	if (s[1] == '?')
	{
		for (int d = 0; d < 10; d++)
			f[1][d % p]++;
	}
	else f[1][(s[1] - '0') % p]++;
	for (int i = 2; i <= n; i++)
	{
		char c = s[i];
		if (c == '?')
		{
			for (int d = 0; d < 10; d++)
				for (int j = 0; j < p; j++)
					f[i][(j * 10 + d) % p] = (f[i][(j + d) % p] + f[i-1][j]) % mod;
		}
		else
		{
			int d = c - '0';
			for (int j = 0; j < p; j++)
				f[i][(j * 10 + d) % p] = (f[i][(j + d) % p] + f[i-1][j]) % mod;
		}
	}
	cout << f[n][0] << endl;
}

int main()
{
	func1();
}